package com.fgxia.driver.controller;

import com.dtflys.forest.annotation.Put;
import com.fgxia.driver.domain.bo.DriverInfoBo;
import com.fgxia.driver.domain.vo.DriverInfoVo;
import com.fgxia.driver.service.IDriverInfoService;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/driver/info")
public class LoginDriverController extends BaseController {

    private final IDriverInfoService driverInfoService;

    /**
     * 添加 driver 用户信息
     * @return
     */
    @RepeatSubmit()
    @PostMapping
    public R<Void> add(@RequestBody DriverInfoBo driverInfoBo) {
        // todo 驾驶证、行驶证、身份证照片等校验
        driverInfoBo.setRelevanceUserId(getUserId());
        Boolean result = driverInfoService.insertByBo(driverInfoBo);
        return toAjax(result);
    }

    /**
     * 查询 driver 用户信息
     * @return
     */
    @GetMapping()
    public R<DriverInfoVo> get() {
        DriverInfoVo driverInfoVo = driverInfoService.selectByUserId(getUserId());
        return R.ok(driverInfoVo);
    }

    /**
     * 更新 driver 用户信息
     * @return
     */
    @PutMapping()
    public R<Void> update(@RequestBody DriverInfoBo driverInfoBo) {
        driverInfoBo.setRelevanceUserId(getUserId());
        boolean result = driverInfoService.updateByBo(driverInfoBo);
        return toAjax(result);
    }
}
